<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
	 <%@ include file="/common/meta.jsp" %>
 	 <%@ include file="/common/import.jsp"%>
    <base href="<%=basePath%>">
    
    <title>会员列表页面</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<style type="text/css">
		#userRegTable,#editTable
		  {
		  font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
		  width:50%;
		  border-collapse:collapse;
		  }
		
		#userRegTable td,#editTable td, #customers th,#editTable th 
		  {
		  font-size:1em;
		  border:1px solid #98bf21;
		  padding:3px 7px 2px 7px;
		  }
		
		#userRegTable th,#editTable th
		  {
		  font-size:1.1em;
		  text-align:left;
		  padding-top:5px;
		  padding-bottom:4px;
		  background-color:#A7C942;
		  color:#ffffff;
		  }
		
		 .alt
		  {
		  color:#000000;
		  background-color:#EAF2D3;
		  }
	</style>
	
	<script>
	function submitForm(formname){		
		var memberEnameValue = $("#memberEname").val();
		
<%--		if($("#memberEnameValue").val()==""||$("#memberEnameValue").val()==null){--%>
<%--			var memberEname=$("#memberEname").html();--%>
<%--			alert("必须填写"+memberEname);--%>
<%--			return ;--%>
<%--		}		--%>
		var realUrl = "";
		if(!confirm("确实要提交吗？")) return;	
		if('add' == formname){
			realUrl = "/admin/member/add.action";
			$.ajax({
				type:'post',
				url:realUrl,
				data:$('#'+formname).serialize(),
				dataType:'json',
				success:function(data){
				      var flag = data.flag;
				      var msg = data.msg;
				      //handleResult(flag,msg);
				      if(flag=="T"){
				        alert("操作成功");
				        document.getElementById("addDiv").style.display = "none";
				        document.getElementById("editDiv").style.display = "block";
				        $("#memberId").val(msg);
				        //document.all.addDiv.style.display = "block";
				        //document.all.editDiv.style.display = "none";
				        //window.location.reload();
				     }else{
				        alert("操作失败");
				     }
					},
				error:function(){
					 alert("请检查服务器！");
					}
				});	
		}else if('edit' == formname){
			realUrl = "/admin/member/edit.action";
			$.ajax({
				type:'post',
				url:realUrl,
				data:$('#'+formname).serialize(),
				dataType:'json',
				success:function(data){
				      var flag = data.flag;
				      var msg = data.msg;
				      //handleResult(flag,msg);
				      if(flag=="T"){
				        alert(msg);
				     }else{
				        alert(msg);
				     }
					},
				error:function(){
					 alert("请检查服务器！");
				}
			});	
			
		}		
			
	}
	function showDiv(oneDiv){
		document.getElementById(oneDiv).style.display = "block";	
		document.getElementById("editDiv").style.display = "none";	
	}
	</script>
	<script type="text/javascript">
		$(function(){
			$('#dataCateList').datagrid({
				title:'会员列表',
				iconCls:'icon-ok',
				url:"${ctx}/admin/member/queryMemberList.action?memberLevel=1",
				nowrap: false,
				striped: true,
				collapsible:false,				
				fitColumns: true,
				pagination:true,
				singleSelect:true,
				rownumbers:true,
				remoteSort: false,
				pageList:[15,20,30,50],
				idField:'memberId',
				columns:[[
					{field:'memberEname',title:'会员名称',width:50},
					{field:'memberCname',title:'会员全称',width:50},
					{field:'shortName',title:'会员简称',width:50},
					{field:'memberType',title:'会员属性',width:50,
						formatter:function(value){
							if( value == '20'){return '个人';}
							else{ return '机构';}
						}
					},
					{field:'clientManagerView',title:'所属负责人',width:50,
						formatter: function(value, rec) {
							var info = "";
							if(rec.clientManager){
								info += " <label style=\"color: green\">已分配</label>"
								info += " | <a href=\"javascript:void(0)\" onclick=\"toGetClientManager('"
									+ rec.memberId
									+ "')\" style=\"color: blue\" title='变更所属负责人'>变更</a> ";
							}else{
								
								info += "<a href=\"javascript:void(0)\" onclick=\"toGetClientManager('"
										+ rec.memberId
										+ "')\" style=\"color: red\" title='分配所属负责人'>未分配</a>";
							}

							return info;
						
						}
					}
				]]
			});		
		});
		
	  //取得数据
	  function getSelected(){
	  	var rec = $('#dataCateList').datagrid('getSelected');
	  	if(rec){
	  		return rec;
	  	}else{
	  		$.messager.alert('提示',"请选择需要操作记录!", 'info');
	  		return null;
	  	}
	  }
		// 查看该会员所拥有的角色
		function viewMemberRole(){
			var obj = getSelected();
			if(obj){
				window.location.href = "${ctx}/admin/memberRole/toList?memberId=" + obj.memberId;
			}
		}
		
		//跳转到分配所属负责人页面
		function toGetClientManager(memberId){
			if(memberId){
				var url = '${ctx}/baseController/member/clientManager/clientManager-save?memberId='+memberId;
				$('#saveClientManagerFrame').attr("title","分配所属负责人");
				$('#saveClientManagerFrame').attr("src",url);
				$('#saveClientManagerDiv').window('open');
				
			}
		}
		
		// 查找
		function searchCate(){
			var queryParams = $('#dataCateList').datagrid('options').queryParams;
			var opt = $('#dataCateList').datagrid('options');
			$('#dataCateList').datagrid('options').pageNumber = 1;
			queryParams["memberEname"] = $('#memberEname').val();
			queryParams["memberCname"] = $('#memberCname').val();
			queryParams["shortName"] = $('#shortName').val();
			var page = $('#dataCateList').datagrid('getPager');
			page.pagination({
				pageNumber : 1,
				pageSize : opt.pageSize
			});
			$('#dataCateList').datagrid('reload');
			<%--var queryParams = $('#dataCateList').datagrid('options').queryParams;	       
	        queryParams.memberEname = $('#memberEname').val();
	        queryParams.memberCname = $('#memberCname').val();
	        queryParams.shortName = $('#shortName').val();
	        var options = $('#dataCateList').datagrid('getPager').data("pagination").options;  
	        options.pageNumber=1;  
	        options.total=0;  
	        options.pageSize=15; 
	        $('#dataCateList').datagrid("reload");
	        $('#query').window('close')--%>;
		}
		
		// 进入增加页面
		function saveCate(){
			//$('#saveFrame').html('');			
			//var url = '${ctx}/admin/member/toAdd.action';				
			//$('#saveFrame').attr("title",'新增会员');
			//$('#saveFrame').attr("src",url);
			//$('#saveDiv').window('open');
			window.location.href = "${ctx}/admin/member/toAdd.action";
		}
		

		// 进入增加回访记录页面
		function toSaveVisit(memberId){
			$('#saveVisitRecordFrame').html('');			
			var url = '${ctx}/admin/visit/toSave?memberId='+memberId;				
			$('#saveVisitRecordFrame').attr("title",'新增回访记录');
			$('#saveVisitRecordFrame').attr("src",url);
<%--			$('#visitMemberId').val(memberId);--%>
			$('#saveVisitRecordDiv').window('open');			
		}
		// 查询会员的访问记录
		function searchVisitList(memberId){
			window.location.href="${ctx}/admin/visit/toList?memberId="+memberId;
<%--			alert(memberId);--%>
<%--			$('#searchVisitRecordFrame').html('');			--%>
<%--			var url = '${ctx}/admin/visit/toList';				--%>
<%--			$('#searchVisitRecordFrame').attr("title",'查询会员的访问记录');--%>
<%--			$('#searchVisitRecordFrame').attr("src",url);--%>
<%--			$('#visitMemberId').val(memberId);--%>
<%--			$('#searchVisitRecordDiv').window('open');			--%>
		}

		
		// 点击取消按钮，关闭添加窗口
		function colseAdd(){
			$('#saveDiv').window('close');
		}
		
		// 刷新列表
		function cateReload(){
			$('#dataCateList').datagrid('reload');
		}
		
		 //关闭win
		 function closeWin(){
		 	$('#saveDiv').window('close');	
		 }
		 
		 //关闭win
		 function closeVisitWin(){
		 	$('#saveVisitRecordDiv').window('close');	
		 }
		 
		 //关闭win
		 function closeClientManagerWin(){
		 	$('#saveClientManagerDiv').window('close');	
		 }
		 
		// 判断是否选中一条记录
		function getSelected(){
			var selected = $('#dataCateList').datagrid('getSelected');
			if (selected){
				return selected;
			}else{
				$.messager.alert('提示', '请选择要操作的数据', 'info');
			}
		}
		
		// 进入修改页面
		function editCate(memberId){
			window.location.href = "${ctx}/admin/member/toEditMember.action?memberId=" + memberId;
			//var node = getSelected();		
			//if (node){	
			//	var url = '${ctx}/admin/member/toEditMember.action?memberId='+node.memberId;
			//	$('#saveFrame').attr("title",node.memberEname);
			//	$('#saveFrame').attr("src",url);
			//	$('#saveDiv').window('open');
			//}
			
		}
		
		//删除，物理删除
		function deleteCate(memberId){					
			//var node = getSelected();	
			//if(node){
		    	$.messager.confirm('确认','您确定要删除 ？',function(r){
		        	if(r){
						$.ajax({
							type: "post",
							url: "/admin/member/delMember.action?memberId=" + memberId,
							dataType: "json",
							success: function(data){
								var flag = data.flag;
							    var msg = data.msg;
	    						if(flag){
									$.messager.alert('结果', '操作成功', 'info');	
								    //var rowIndex = $('#dataCateList').datagrid('getRowIndex',node);								
								   // $('#dataCateList').datagrid('deleteRow', rowIndex);	
									$('#dataCateList').datagrid('reload');
	    						}else{
	    							$.messager.alert('结果', '操作失败，请重试', 'error');	
	    						}
							},
							error:function(messg)  { 
					       	    $.messager.alert('错误提示', '操作失败:'+messg.responseText, 'error');
					       } 
						});
		          	}
		       });		             		
		   // }	
		}
		
	</script>

  </head>
  <body>
  	 <!-- 查询窗口 -->
	<div id="query" class="easyui-window" title="查询" style="padding:5px;width:400px;height:250;"
    	iconCls="icon-search" closed="true" maximizable="false" minimizable="false" collapsible="false">
		<table class="datagrid-body" >
			<tr>	
				<td class="datagrid-header">用户账号：</td>
				<td><input type="text" id="memberEname" name="memberEname" size="30" value="" /></td>
			</tr>
			
			<tr >
				<td class="datagrid-header">用户名称：</td>
				<td><input type="text" id="memberCname" name="memberCname" size="30" value="" /></td>
			</tr>

			<tr >
				<td class="datagrid-header">用户简称：</td>
				<td><input type="text" id="shortName" name="shortName" size="30" value="" /></td>
			</tr>
			<tr>	
				<td class="datagrid-header"></td>
				<td><a href="#" class="easyui-linkbutton" iconCls="icon-search" onClick="searchCate();">查找</a></td>	
			</tr>
		</table>
     </div>
    
     <!-- 修改窗口 -->
 	 <div id="saveDiv" class="easyui-window" title="修改会员" style="padding:5px;width: 700px;height:450px;"
    	iconCls="icon-search" closed="true" maximizable="false" minimizable="false" collapsible="false">
   		<iframe frameborder="0"  id="saveFrame" height="100%" width="100%" scrolling="auto" frameborder="0" ></iframe>
     </div>
     <table id="dataCateList"></table>

     
 	 <div id="saveVisitRecordDiv" class="easyui-window" title="新增回访记录" style="padding:5px;width: 350px;height:450px;top:100px;"
    	iconCls="icon-search" closed="true" maximizable="false" minimizable="false" collapsible="false">
   		<iframe frameborder="0"  id="saveVisitRecordFrame" height="100%" width="100%" scrolling="auto" frameborder="0" >
   		</iframe>
     </div>
 	 <div id="saveClientManagerDiv" class="easyui-window" title="分配所属负责人" style="padding:5px;width: 400px;height:300px;top:100px;"
    	iconCls="icon-search" closed="true" maximizable="false" minimizable="false" collapsible="false">
   		<iframe frameborder="0"  id="saveClientManagerFrame" height="100%" width="100%" scrolling="auto" frameborder="0" >
   		</iframe>
     </div>
     
    
    

  </body>
</html>
